﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using tiDE;

namespace GenerateTable
{
    public partial class GUIManager : Form
    {
        public List<OPCode> Opcodes, SecondaryOpcodes;

        public GUIManager(List<OPCode> OPCodes)
        {
            InitializeComponent();
            Opcodes = OPCodes;
            SecondaryOpcodes = new List<OPCode>();
            UpdateList();
        }

        void UpdateList()
        {
            listBox1.Items.Clear();
            foreach (OPCode opcode in Opcodes)
                listBox1.Items.Add(opcode.Match);
            listBox2.Items.Clear();
            foreach (OPCode opcode in SecondaryOpcodes)
                listBox2.Items.Add(opcode.Match);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = listBox1.SelectedIndices.Count - 1; i >= 0; i--)
            {
                SecondaryOpcodes.Add(Opcodes[listBox1.SelectedIndices[i]]);
                Opcodes.RemoveAt(listBox1.SelectedIndices[i]);
            }
            SecondaryOpcodes.Reverse();
            UpdateList();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = listBox2.SelectedIndices.Count - 1; i >= 0; i--)
            {
                Opcodes.Insert(listBox1.SelectedIndex,
                    SecondaryOpcodes[listBox2.SelectedIndices[i]]);
                SecondaryOpcodes.RemoveAt(listBox2.SelectedIndices[i]);
            }
            UpdateList();
        }
    }
}
